Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Admin Dashboard - User Profiles #1328

Merged
merged 30 commits into from
Dec 29, 2024

Conversation

JPKribs
Copy link
Member

@JPKribs JPKribs commented Nov 26, 2024

Summary

Allows for editing/deleting a user image. This is just repurposing the existing UserProfileImagePicker to be callable from both current userSession or another user. Also allows for editing a user's account name.

This edits the layout of the ServerUserDetailView to be more in line with the UserProfileView

Screenshots

Updated View Updated View Screenshot
Update Username Updated View Screenshot
Image Options Username Editor Screenshot

@JPKribs
Copy link
Member Author

JPKribs commented Nov 26, 2024

This is currently 'ready' but the notification to update the image on update isn't firing 100% of the time. So sometimes, when I change a user image it just never changes even though it's been updated on the server. Happens about 50% of the time so I think I have an issue on my end to work out.

@LePips
Copy link
Member

LePips commented Nov 26, 2024

I've played around with this and I don't think that the issue is due to the notification being sent but a caching issue. If I edit the profile image for a different user then nothing will be properly updated for that user, even on the user sign in view. If I exit the admin user and then sign into the user I edited, then all of the images will appear properly.

@JPKribs
Copy link
Member Author

JPKribs commented Nov 26, 2024

Interesting. What is being done on the local user level to clear the cache on pfp update? I tried to mirror/reuse what I could but I could have missed something. Plus, I need to clean up this PR a bit it's a little hectic...

@JPKribs JPKribs changed the title [iOS] Admin Dashboard - Profile Editing [iOS] Admin Dashboard - User Profiles Nov 27, 2024
@JPKribs
Copy link
Member Author

JPKribs commented Nov 27, 2024

Daw, I merged it wrong...

This branch is broken but I needed to redo this anyway. I'm going to wipe and try again here off of Main later this week.

@JPKribs JPKribs changed the title [iOS] Admin Dashboard - User Profiles [WIP] [iOS] Admin Dashboard - User Profiles Dec 11, 2024
@JPKribs JPKribs closed this Dec 12, 2024
@JPKribs JPKribs force-pushed the adminDashboardProfile branch from 28121a0 to d001a96 Compare December 12, 2024 21:50
…set image / other stuff like delete & username.
@JPKribs JPKribs reopened this Dec 12, 2024
@JPKribs JPKribs marked this pull request as ready for review December 14, 2024 07:44
@JPKribs
Copy link
Member Author

JPKribs commented Dec 14, 2024

This should be good but I'm back to having the same issue as before where I'm unable to get images to refresh appropriately throughout. Going from no image -> image works appropriately but image -> new image doesn't always refresh. Is that image caching or did I screw up the notifications?

There is also a weird one where if you change your username from Server Users -> Server User Details it doesn't update for the settings. The reason for this is I'm not sure how to update the userSession.user.name.

Last item, I am using the UserID as the payload for didChangeUserProfile. If I change that to UserDto, that would be a bigger payload but it would also mean I can refresh the user once at update then use that across multiple ViewModels because I think right now there is a chance that like 2 refreshes for the same data can occur?

🎉 This should be the final Admin Dashboard PR until we update to 10.10 🎉

@JPKribs JPKribs changed the title [WIP] [iOS] Admin Dashboard - User Profiles [iOS] Admin Dashboard - User Profiles Dec 14, 2024
Copy link
Member

@LePips LePips left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As some clarification, the current UserProfileHeroImage should be UserProfileImage. The Hero attribute should be used for the views that have the profile image as the large image, which then can use UserProfileImage.

@JPKribs
Copy link
Member Author

JPKribs commented Dec 19, 2024

Ah! I probably should have googled that first haha... I've updated this to reflect what the names should be!

@JPKribs
Copy link
Member Author

JPKribs commented Dec 21, 2024

I was just briefly looking at Nuke. When we update a UserProfileImage, I added:

        .onNotification(.didChangeUserProfile) { notificationUser in
            if notificationUser == userId {
                let imageURL = source.url

                guard let imageURL else {
                    logger.info("No user profile image URL found")
                    return
                }

                let request = ImageRequest(url: imageURL)

                pipeline.cache[request] = nil
                pipeline.configuration.dataCache?.removeData(for: imageURL.absoluteString)
                logger.info("Image removed from cache: \(imageURL.absoluteString)")
            }
        }

The result of this is that ServerUsers profile images are appropriately getting cleared and replaced when the image updates! From my google, this looks right but let me know if this isn't the way to go!

This PR should be ready for a second look I think!

@JPKribs JPKribs requested a review from LePips December 23, 2024 07:19
@LePips
Copy link
Member

LePips commented Dec 24, 2024

Debugging this a little bit further I see a larger issue: most images aren't cached at all in the expected directories. The only images that are cached as expected are the splash screens. For the rest of the images, the name generator that is used makes invalid filenames.

maxWidth is an issue since it would cause different keys for the same images just at different sizes. I'm pursuing a new caching system to help with that as well as hopefully some performance improvements, but I won't let that stop this.

@JPKribs
Copy link
Member Author

JPKribs commented Dec 24, 2024

Debugging this a little bit further I see a larger issue: most images aren't cached at all in the expected directories. The only images that are cached as expected are the splash screens. For the rest of the images, the name generator that is used makes invalid filenames.

Is that a Nuke issue or have I been using Nuke incorrectly? Is the .onNotification I did here the correct usage or will that need to change?

maxWidth is an issue since it would cause different keys for the same images just at different sizes. I'm pursuing a new caching system to help with that as well as hopefully some performance improvements, but I won't let that stop this.

I didn't even think about that for the URL maxWidth. Is there anything on my end that I can help with? Sorry, I feel like I've been creating a lot of additional work for you so please let me know if there is anything I can do to help out!

@LePips
Copy link
Member

LePips commented Dec 24, 2024

Nah, I've just been holding Nuke incompletely. The widths-causing-different keys has long been on my mind since I first implemented the caching but the lack-of-caching is new to me.

It's just that since now we need to manipulate the caches, the need for a better implementation is more pressing.

@LePips
Copy link
Member

LePips commented Dec 29, 2024

I have largely refactored our image caches to, well, work as expected. I've taken a lot of time to really understand our use case of images since on the server images are keyed by the item id, a tag, and image sizes which causes issues on our side for cache invalidation. The total implementation is not complete and I will be asking the creator of Nuke some clarifying questions to fit our use case a little bit more.

You should run through this really quick to check that the user images update as expected.

@JPKribs
Copy link
Member Author

JPKribs commented Dec 29, 2024

You should run through this really quick to check that the user images update as expected.

This works great! This is going to help a ton with #1345 as well! I only found 2 things. One was a comment that said 500mb when it was 1000mb and one was updating tvOS to use the new cache to get it to build.

Tested on both iOS and tvOS and everything is working as expected for the areas that we touched with this PR. All images update appropriately now on change, including the logged in user's image. Both locations have the same logic, but I have confirmed both editing your user from Settings > User and Settings > Dashboard > Users > User both work appropriately and are both reflected in both positions. That is, updating from one locations reflects everywhere it's used throughout Swiftfin. I think you nailed it with this change!

Tested tvOS as well. We don't have any logic there to update user images, nor should we IMO so there is less to change. That being said, the images are where they are expected to be and there are no weird caching side effects that I can see!


The only thing that's a little weird (and this was weird before your changes) is that the caching behaves weirdly on the UserSignInView. If I switch to a new server, it uses the images from the previously selected server:

Simulator Screenshot - Apple TV 4K (3rd generation) - 2024-12-28 at 18 30 15
Simulator Screenshot - Apple TV 4K (3rd generation) - 2024-12-28 at 18 30 25

This is behaving in the same way as before this PR so I don't think we need to fix it for this PR. Just something where, if you knew what was causing this on the caching side, might be nice to make a quick swap on. Otherwise, if we need to do. some digging, I can do that later on another PR!

@LePips
Copy link
Member

LePips commented Dec 29, 2024

Thank you for those fixes and testing that. It looks like we'll have to stick an id somewhere on that view.

@LePips LePips merged commit 23beb08 into jellyfin:main Dec 29, 2024
4 checks passed
@JPKribs JPKribs deleted the adminDashboardProfile branch December 29, 2024 06:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants